package org.stormphoenix.bbsfamily.dao

import org.apache.ibatis.annotations.*
import org.apache.ibatis.mapping.FetchType
import org.apache.ibatis.type.JdbcType
import org.springframework.stereotype.Component
import org.stormphoenix.bbsfamily.entity.UserDO

@Mapper
@Component
interface UserMapper {
    // TODO 考虑一下 fetchType = FetchType.EAGER 的效率问题
    @Select("SELECT * FROM user WHERE username = #{username}")
    @Results(
        Result(id = true, column = "id", property = "id"),
        Result(column = "reg_time", property = "regTime", jdbcType = JdbcType.TIMESTAMP),
        Result(
            column = "id",
            property = "roles",
            many = Many(
                select = "org.stormphoenix.bbsfamily.dao.RoleMapper.findRolesByUserId",
                fetchType = FetchType.EAGER
            )
        )
    )
    fun findUserByUsername(@Param(value = "username") username: String): UserDO?
}